<template>
  <div>
    <el-popover placement="bottom-end" v-model="visiblePatient" trigger="focus">
      <el-input
        :placeholder="Ptext"
        slot="reference"
        v-model="params.people_name"
        @input="getpatientList()"
      >
      </el-input>

      <el-table
        v-loading="patientLoading"
        @current-change="xuanzePatient"
        highlight-current-row
        height="300"
        :data="
          peopleData.filter(
            (data) =>
              !params.people_name ||
              data.real_name.toLowerCase().includes(params.people_name.toLowerCase())
          )
        "
      >
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>

        <el-table-column
          width="100"
          property="number"
          label="编码"
        ></el-table-column>
        <el-table-column
          width="200"
          property="real_name"
          label="name"
        ></el-table-column>

        <el-table-column
          width="150"
          property="dept_name"
          label="科室"
        ></el-table-column>
      </el-table>
      <el-pagination
        :current-page="params.page"
        :page-size="params.limit"
        @current-change="pageUser"
        :total="params.peopleCount"
        layout="prev, pager, next"
      >
      </el-pagination>
    </el-popover>
  </div>
</template>    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
<script>
let t;
import { mapState, mapMutations, mapActions } from "vuex";
export default {
  name:"dialogTableUser",
  data() {
    return {
      visiblePatient: false,
      patientLoading: false,
      params: {
        people_name: "",
        people_id: "",
        page: 1,
        limit: 10,
        peopleCount: 0,
      },
      peopleData: [],

   
    };
  },
  mounted() {
    t = this;
    this.getpatientList();

    if (this.drugCollarDetail.drug_item) {
      this.params.people_name =
        this.drugCollarDetail[this.setVal[this.typeName]].real_name;
    }
  },
  methods: {
    ...mapMutations([
      "storage/set_drugCollarDetail",
      "storage/set_drugCollarDetailRetreat",
      "storage/set_into_storeShow",
    ]),

    pageUser(e) {
      this.params.page = e;
      this.getpatientList();
    },
    xuanzePatient(item) {
      if (item) {
        console.log(item);

        this[this.funName]({ key: this.typeName, val: item.id });

        this.params.people_name = item.real_name;
        this.visiblePatient = false;
      }
    },
    getpatientList() {
      this.patientLoading = true;
      this.peopleData = [];
      let d = {
        keyword: this.params.people_name,
        page: this.params.page,
        limit: this.params.limit,
      };
      this["_API"].getUserIndex(d).then((res) => {
        this.patientLoading = false;
        if (res.code == 200) {
          this.peopleData = res.data.list;
          this.params.peopleCount = res.data.count;
        }
      });
    },
  },
  props: ["typeName", "that", "funName",'setVal','Ptext'],
  computed: {
    ...mapState({
      drugCollarDetail: (state) => {
      
        if (t.funName=="storage/set_drugCollarDetail") {
          return state.storage.drugCollarDetail;
        } else if (t.funName=="storage/set_drugCollarDetailRetreat") {
          return state.storage.drugCollarDetailRetreat;
        } else if (t.funName == "storage/set_into_storeShow") {
          return state.storage.into_storeShow;
        }
      },
    }),
  },
};
</script>

<style lang="scss" scoped>
</style>